<template>
    <div class="goods-list">
        <div @click="goDetail(item.id)" class="goods-item" v-for="item in goodslist" :key="item.id">
            <img :src="item.img_url" alt="">
            <h1 class="title">{{item.title}}</h1>
            <div class="info">
                <p class="price">
                    <span class="now">￥{{item.sell_price}}</span>
                    <span class="old">￥{{item.market_price}}</span>
                </p>
                <p class="cell">
                    <span >热卖中</span>
                    <span >剩{{item.stock_quantity}}件</span>
                </p>
            </div>
        </div>
        <mt-button type="danger" size="large">加载更多</mt-button>
    </div>
</template>
<script>
export default {
  data() {
    return {
      goodslist: []
    };
  },
  created() {
    this.getGoodsList();
  },
  methods: {
    getGoodsList() {
      this.goodslist = [
        {
          id: 1,
          title:
            "华为 HUAWEI Mate 20 麒麟980AI智能芯片全面屏超微距影像超大广角徕卡三摄",
          add_time: "2012-12-12 12:12:12",
          zhaiyao: "深空灰色",
          click: 1,
          img_url:
            "https://img11.360buyimg.com/n7/jfs/t25954/134/1930444050/488286/31587d0d/5bbf1fc9N3ced3749.jpg",
          sell_price: 8856.0,
          market_price: 9000,
          stock_quantity: 20
        },
        {
          id: 2,
          title:
            "Apple iPhone 8 Plus 64GB 红色特别版 移动联通电信4G手机 后置双摄，双面玻",
          add_time: "2012-12-12 12:18:12",
          zhaiyao: "以官网信息为准",
          click: 35,
          img_url:
            "https://img13.360buyimg.com/n7/jfs/t23167/95/285071867/94556/c98fa4f6/5b2b6212N106d8382.jpg",
          sell_price: 8752,
          market_price: 8999,
          stock_quantity: 100
        },
        {
          id: 3,
          title:
            "一加手机6 8GB+128GB 亮瓷黑 全面屏双摄游戏手机 全网通4G 双卡双待 领券立减",
          add_time: "2012-12-12 12:17:12",
          zhaiyao: "WIFI；蓝牙；WiFi热点",
          click: 24,
          img_url:
            "https://img13.360buyimg.com/n7/jfs/t22519/185/2357218296/213888/ff5e9aa3/5b7bd314N6db24355.jpg",
          sell_price: 1456.0,
          market_price: 23456,
          stock_quantity: 5
        }
      ];
      this.$http
        .get("https://www.baidu.com/?tn=62095104_7_oem_dg")
        .then(result => {
          console.log(result);
        });
    },
    goDetail(id) {
      this.$router.push({name:"goodsinfo",params:{id}});
    }
  }
};
</script>
<style lang="scss" scoped>
.goods-list {
  background-color: #fff;
  display: flex;
  flex-wrap: wrap;
  padding: 7px;
  justify-content: space-between;
  .goods-item {
    padding: 2px;
    border: 1px solid #ccc;
    width: 49%;
    box-shadow: 0 0d 8px #ccc;
    margin: 3px 0;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 293px;
    img {
      width: 100%;
    }
    .title {
      font-size: 14px;
    }
    .info {
      background-color: #ddd;
      p {
        margin: 0;
        padding: 5px;
      }
      .price {
        .now {
          color: red;
          font-weight: bold;
          font-size: 16px;
        }
        .old {
          text-decoration: line-through;
          font-size: 12px;
          margin-left: 10px;
        }
      }
      .cell {
        display: flex;
        justify-content: space-between;
      }
    }
  }
}
</style>

